package com.zg.sso.web;

import com.zg.common.core.R;
import com.zg.sso.req.*;
import com.zg.sso.service.ZtService;
import com.zg.sso.vo.SsoLoginVo;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequiredArgsConstructor
public class ZtController {
    //单点登录
    //登出
    //刷新token
    //同步用户信息
    //获取其他系统单点登录地址

    private final ZtService ztService;

    /**
     * 统一认证登录
     *
     * @param param
     * @return
     */
    @PostMapping("/zt/sso/login")
    public R<SsoLoginVo> ssoLogin(@RequestBody @Valid SsoLoginReq param) {
        SsoLoginVo ssoLoginVo = ztService.ssoLogin(param);
        return R.success(ssoLoginVo);
    }

    /**
     * 统一认证登出
     *
     * @param param
     * @return
     */
    @PostMapping("/zt/sso/logout")
    public R<String> ssoLogout(@RequestBody @Valid SsoLogoutReq param) {
        String result = ztService.ssoLogout(param);
        return R.success(result);
    }

    /**
     * 统一认证刷新token
     *
     * @param param
     * @return
     */
    @PostMapping("/zt/sso/refreshToken")
    public R<String> ssoRefreshToken(@RequestBody @Valid SsoRefreshTokenReq param) {
        String result = ztService.ssoRefreshToken(param);
        return R.success(result);
    }

    /**
     * 同步用户信息
     *
     * @param param
     * @return
     */
    @PostMapping("/zt/sso/syncUserInfo")
    public R<String> syncUserInfo(@RequestBody @Valid SsoSyncUserInfoReq param) {
        String result = ztService.syncUserInfo(param);
        return R.success(result);
    }

    /**
     * 获取其他系统统一认证登录地址
     *
     * @param param
     * @return
     */
    @PostMapping("/zt/sso/getOtherSystemLoginUrl")
    public R<String> getOtherSystemLoginUrl(@RequestBody @Valid SsoGetOtherSystemLoginUrlReq param) {
        String otherSystemLoginUrl = ztService.getOtherSystemLoginUrl(param);
        return R.success(otherSystemLoginUrl);
    }


}
